﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：DataAccessConyifutype
// 文件功能描述：洗衣类型维护数据访问层
//
// 
// 创建标识：2012-07-13 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DbAdapter.sqldbAdapter;
using System.Data.SqlClient;

namespace DAO.WaiGaoQiao
{
    public class DataAccessConyifutype
    {

        public DataSet GetList(int pagesize, int startindex, string strquery)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                string query = "select * from (select ROW_NUMBER() OVER(ORDER BY Yifu_ID ASC) rownumber,* " +
                               "from Con_yifutype where 1=1 " + strquery + ") B "
                             + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString();
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        public int GetCount(string strquery)
        {
            sqldb db = new sqldb();
            string query = "select count(1) from Con_yifutype where 1=1 " + strquery;
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }


        public int DeleteConyifutype(string id)
        {
            sqldb db = new sqldb();
            string query = "select count(*) from Con_xiyijilu where Yifu_ID in(" + id + ")";
            int rowcount = Convert.ToInt32(db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query));
            if (rowcount > 0)
            {
                rowcount = 0;
            }
            else
            {
                query = "Delete from Con_yifutype where Yifu_ID in(" + id + ")";
                rowcount = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
            }
            return rowcount;
        }

        public int SaveAdd(object[] yax)
        {
            sqldb db = new sqldb();
            string query = "insert into Con_yifutype(Yifumc,Count_xiyi) Values('" +
                yax[0] + "','" + Convert.ToInt32(Convert.ToDecimal(yax[1]) * 100) + "')";
            int rowcount = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
            return rowcount;
        }

        public DataSet GetInfoOne(string id)
        {
            sqldb db = new sqldb();
            string query = "select * from Con_yifutype where Yifu_ID = '" + id + "'";
            return db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
        }

        public int SaveEdit(object[] supp)
        {
            sqldb db = new sqldb();
            string query = "update Con_yifutype set Yifumc='" + supp[1] + "',Count_xiyi='" + Convert.ToInt32(Convert.ToDecimal(supp[2]) * 100) + "' where Yifu_ID=" + supp[0];
            int rowcount = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
            return rowcount;
        }
    }
}
